package com.mall.shopping.services;

import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hsp
 * @date 2021/5/24 16:23
 */
@Service
public class IProductCateServiceImpl implements IProductCateService {
    @Autowired
    ItemCatMapper itemCatMapper;
    @Autowired
    ProductCateConverter productCateConverter;
    @Override
    public AllProductCateResponse getAllProductCate(AllProductCateRequest request) {


        List<ProductCateDto> productCateDtos = new ArrayList<>();

        List<ItemCat> itemCats = itemCatMapper.selectAll();
        for (ItemCat itemCat : itemCats) {
            ProductCateDto productCateDto = productCateConverter.item2Dto(itemCat);
            productCateDtos.add(productCateDto);
        }
        AllProductCateResponse allProductCateResponse = new AllProductCateResponse();
        allProductCateResponse.setProductCateDtoList(productCateDtos);
        allProductCateResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
        allProductCateResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return allProductCateResponse;
    }
}
